package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import rmi.Session;

public class GUIMark extends JPanel{
	
	private static final long serialVersionUID = 1L;
	private JLabel lbInfo;
	private JLabel lbInfo1;
	private JLabel lbMark;
	private JButton btExit;
	
	public GUIMark(final Session session) {
		setOpaque(false);
		lbInfo = new JLabel("BẠN ĐÃ HOÀN THÀNH XONG KHOÁ THI");
		lbInfo.setFont(lbInfo.getFont().deriveFont(30f));
		lbInfo.setForeground(Color.DARK_GRAY);
		lbInfo1 = new JLabel("Số điểm bạn đạt được là: ");
		lbInfo1.setFont(lbInfo.getFont().deriveFont(20f));
		lbInfo1.setForeground(Color.DARK_GRAY);
		lbMark = new JLabel();
		lbMark.setFont(lbInfo.getFont().deriveFont(50f));
		lbMark.setForeground(Color.RED);
		try {
			double mark = session.getMark();
			lbMark.setText(String.format("%1$,.2f", mark));
		} catch (RemoteException | SQLException e) {
			e.printStackTrace();
		}
		
		btExit = new CustomJButton("x", 40, 40, Color.WHITE, CustomJButton.DARKER,
				Color.DARK_GRAY, 2, true, true);
		btExit.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				try {
					session.logout();
				} catch (RemoteException e) {
					e.printStackTrace();
				}
				System.exit(-1);
			}
		});
		
		setLayout(new BorderLayout());
		setBorder(new EmptyBorder(10, 10, 10, 10));
		JPanel panel = new JPanel(new GridBagLayout());
		panel.setOpaque(false);
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 1;
		panel.add(lbInfo,c);
		c.gridx = 0;
		c.gridy = 1;
		panel.add(lbInfo1,c);
		c.gridx = 0;
		c.gridy = 2;
		panel.add(lbMark,c);
		add(panel,BorderLayout.CENTER);
		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		buttonPanel.setOpaque(false);
		buttonPanel.add(btExit);
		add(buttonPanel,BorderLayout.SOUTH);
	}
}
